package com.css.resoft.p2pmonitor.test;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;

public class UnZipFile {
	
	public static void main(String[] args) throws IOException {
		
		String fileDir = "D:\\p2p";
		List<String> filePaths = new ArrayList<String>();
		getFileList(fileDir,filePaths);
		
		for (String file : filePaths) {
			System.out.print("zipfile: "+file );
			ZipFile zf = new ZipFile(file);
			ZipInputStream zin = new ZipInputStream(new BufferedInputStream(new FileInputStream(file))); 
			ZipEntry ze; 
			while((ze = zin.getNextEntry())!=null){
				if(!ze.isDirectory()){
					zin.closeEntry();
					
					long size = ze.getSize();
					System.out.print("  xmlfile: "+ze.getName()+" size: " + size);
				}
			}
			
			zin.close();
			zf.close();
			System.out.println();
		}
		
		
	}
		
	public static void getFileList(String fileDir, List<String> filePaths) {
		File file = new File(fileDir);
		if(file.isFile() && fileDir.endsWith("zip")){
			filePaths.add(fileDir);
		}else if(file.isDirectory()){
			for(String str: file.list()){
				getFileList(fileDir+"\\"+str,filePaths);
			}
		}
	}
}
